package com.insigma.business.qrcode.welfare.util;

import com.insigma.business.qrcode.common.util.RedisUtils;
import com.insigma.business.qrcode.soldier.dto.SoldierOuterLoginAccountDTO;
import com.insigma.business.qrcode.soldier._consumer.SoldierConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("userUtils")
@Slf4j
public class UserUtils {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private SoldierConsumer soldierConsumer;

    public String getCachedSoldierName(String soldierUserId) {
        String key = "soldier_name_" + soldierUserId;
        Object o = redisUtils.get(key);
        if (o == null) {
            SoldierOuterLoginAccountDTO outer = soldierConsumer.getSoldierOuterLoginAccountBySoldierId(soldierUserId).getDto();
            o = outer.getOuterSysNickName();
            redisUtils.set(key, outer.getOuterSysNickName(), 10 * 60);
        }
        return (String) o;
    }

}
